package net.ocps.tchs.soap.entity;

import java.util.ArrayList;

import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.physics.box2d.Body;

import net.ocps.tchs.soap.event.EventA;
import net.ocps.tchs.soap.event.EventC;

public abstract class Entity {
	
	public Entity( int... coords ) {
		x = coords[ 0 ];
		y = coords[ 1 ];
		hitbox = new Rectangle( x, y, width, height );
	}
	
	public Entity( float x, float y, int width, int height ) {
		this( (int)x, (int)y );
	}
	
	public Entity( float x, float y, int width, int height, String Image ) {
		this( (int)x, (int)y );
		imagePath = Image;
	}
	
	public abstract void onCreate( );
	public abstract void render( );
	
	/* DONT CALL THIS METHOD, THIS IS FOR THE EVENT SYSTEM */
	public int sendEvent( EventA e ) {
		if( e == null )
			return 1;
		e.process( this );
		
		return 0;
	}
	
	public void queueEvent( EventA e ) {
		events.add( e );
	}
	public float getX() {
		return x;
	}
	
	public float getY() {
		return y;
	}
	
	public void setX( float x ) {
		if( jumpCounter <= 0 )
			body.setLinearVelocity( x, body.getLinearVelocity().y );
		else {
			if( !((body.getLinearVelocity().x > 50 && direction == 1) || (body.getLinearVelocity().x < -50 && direction == -1) ) ) {
				body.applyForceToCenter( x, 0);
			}
		}
	}
	
	public void setY( float y ) {
		body.setLinearVelocity( body.getLinearVelocity().x, y );
	}
	
	public void addX( float x ) {
		body.applyForceToCenter( x, body.getLinearVelocity().y);
	}
	
	public void addY( float y ) {
		body.applyForceToCenter( body.getLinearVelocity().x, body.getLinearVelocity().y+y );
	}
	
	protected float x, y;
	String imagePath = "";
	public Rectangle hitbox;
	public int jumpCounter = 0;
	public int width = 0, height = 0;
	public int direction;
	public SpriteBatch batch;
	public Sprite texture;
	public Body body;
	public EventA mainEvent;
	public EventC collisionEvent;
	public ArrayList<EventA> events = new ArrayList<EventA>();
}
